$(function() {
$('#tt').datagrid({  
    width: '100%',  
    height: 465,  
    nowrap: false,  
    striped: true,  
    border: true,  
    collapsible:false,// 是否可折叠的
//    fit: true,//自动大小
    url:'/edu/lesson/getLessonClassif',  
    // sortName: 'code',
    // sortOrder: 'desc',
    remoteSort:false,   
    idField:'classif_id',  
    singleSelect:true,// 是否单选
    pagination:true,// 分页控件
    rownumbers:true,// 行号
    frozenColumns:[[  
        {field:'ck',checkbox:true}  
    ]],  
    toolbar: [{  
        text: '添加',  
        iconCls: 'icon-add',  
        handler: function() {  
            openDialog("add");  
        }  
    }, '-', {  
        text: '修改',  
        iconCls: 'icon-edit',  
        handler: function() { 
// alert("edit");
            openDialog("edit");  
        }  
    }, '-',{  
        text: '删除',  
        iconCls: 'icon-remove',  
        handler: function(){  
    	deleteData();
        }  
    }],  
});  
// 设置分页控件
var p = $('#tt').datagrid('getPager');  
$(p).pagination({  
    pageSize: 15,// 每页显示的记录条数，默认为10
    pageList: [15,20],// 可以设置每页记录条数的列表
    beforePageText: '第',// 页数文本框前显示的汉字
    afterPageText: '页    共 {pages} 页',  
    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',  
    /*
	 * onBeforeRefresh:function(){ $(this).pagination('loading'); alert('before
	 * refresh'); $(this).pagination('loaded'); }
	 */ 
});  
});


function openDialog(model){
	var row;
	if(model=="add"){
		$('#id').val(-1);
		$('#dlg').panel({title:"课程分类信息-新增"});
		$('#dlg').window('open');
		}
	else if(model=="edit"){
	// loadUe();
		// var ue = UE.getEditor("container");
		row = $('#tt').datagrid('getSelected');
		if(row==null){
			$.messager.alert("提示","请选择要修改的行","info");
		}else{
			$('#id').val(row.classif_id);
			$('#name').val(row.name);
			$('#description').val(row.description);
			// 获取classif 信息
			// ue.ready(function() {
			    // 设置编辑器的内容
		// ue.setContent(row.description);
		// });
		// $('#id').val(row.classif_id);
		// $("#tabs").tabs("select", 1);
			$('#tabs').tabs('disableTab', 0);
			$('#dlg').window('open');
		}
		}else if(model=="delete"){
			
			}else{
				}
}

function save()
{
	var urlStr;
var classif_idStr=$('#id').val();
if(classif_idStr==-1){
	urlStr="/edu/lesson/addLessonClssif";
}else{
	urlStr="/edu/lesson/updateLessonClassif";
}

var nameStr=$('#name').val();
var descriptionStr = $('#description').val();
//$.messager.alert("提示","id:"+classif_idStr+"<br />name:"+nameStr+"<br />description:"+descriptionStr,"info");

$.ajax({
	url: urlStr,
	type: "POST",
	data:{
		classif_id:classif_idStr,
		name:nameStr,
		description:descriptionStr
	},
	dataType: "json",
	async: false,
	success: function(data) {
		if (data.status) {
			$.messager.alert("提示",data.msg,"info");
	}else{
		$.messager.alert("提示",data.msg,"error");
		}
	}});

$('#dlg').window('close');
$("#tt").datagrid('reload');  
}

function deleteData(){
var	row = $('#tt').datagrid('getSelected');
	if(row==null){
		$.messager.alert("提示","请选择要删除的行","info");
	}else{
		var classif_idStr= row.classif_id;
		if(classif_idStr>0)
		{
			$.ajax({
				url: "/edu/lesson/deleteLessonClassif",
				type: "POST",
				data:{
					classif_id:classif_idStr,
				},
				dataType: "json",
				async: false,
				success: function(data) {
					if (data.status) {
						$.messager.alert("提示",data.msg,"info");
				}else{
					$.messager.alert("提示",data.msg,"error");
					}
				}});
			$("#tt").datagrid('reload');  
		}else{
			$.messager.alert("提示","非法数据修改！","error");
		}
		
	}
}

